let params = {
	data: {},
	meta: {
		user_id: uni.getStorageSync("uid") || "",
		token: uni.getStorageSync("token") || "",
	}
};

let API_URL = 'http://localhost:8080/remember/wxapi.';

const request = (url, method, data, isUpload = false) => {
	return new Promise((resolve, reject) => {
		params.data = data;
		if (!isUpload) {
			uni.request({
				header: {
				  "content-type": "application/json"
				},
				url: API_URL + url,
				method: method,
				dataType: 'json', //返回值类型
				data: params,
				success: (res) => { //具体捕获请看自己接口返回的形式
					if (res.data.meta.code == 200 || res.data.meta.code == 0 || res.data.meta.code == 1204) {
						resolve(res)
					}
				},
				fail(error) {
					reject(error)
				},
				complete() {

				}
			});
		} else {
			uni.uploadFile({
				url: _url,
				filePath: data,
				name: 'file',
				header: {
					'X-Access-Token': TOKEN
				},
				formData: {
					file: data,
					fileType: '1',
					pathType: "1"
				},
				success: (uploadFileRes) => {
					let parms = JSON.parse(uploadFileRes.data)
					let imgurls = parms.result.filePath
					resolve(imgurls)
				},
				fail: () => {
					uni.showToast({
						title: '图片上传失败',
						icon: 'none'
					})
				}
			});
		}

	})
}

export{
	request, //向外暴露request
	params
}
